package summer.hot100.v1;

import java.util.List;

public class Solution139 {
    public boolean wordBreak(String s, List<String> wordDict) {
        int n = s.length();
        boolean[] dp = new boolean[n + 1];
        dp[0] = true;
        for (int i = 1; i < n + 1; i++) {
            for (int j = 0; j < wordDict.size(); j++) {
                String cur = wordDict.get(j);
                if (i >= cur.length() && s.substring(i - cur.length(), i).equals(cur) && dp[i - cur.length()]) {
                    dp[i] = true;
                    break;
                }
            }
        }
        return dp[n];
    }
}
